package com.wc.alorithm_blue_bridge._枚举.特别数的和;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/10/11 11:54
 * @description 特别数的和
 * https://www.lanqiao.cn/problems/191/learning/?page=2&first_category_id=1&sort=students_count&second_category_id=3
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ans = 0;
        int[] comparison = new int[]{2, 0, 1, 9};
        while (n > 0) {
            /**
             * 当前数
             */
            int num = n;
            while (num != 0) {
                /**
                 * 余数
                 */
                int remainder = num % 10;
                /**
                 * 检查是否有满足要求的
                 */
                boolean flg = false;
                /**
                 * 对比是否尾数为2 0 1 9
                 */
                for (int i = 0; i < comparison.length; i++) {
                    if (remainder == comparison[i]) {
                        flg = true;
                        break;
                    }
                }
                if (flg) {
                    ans += n;
                    break;
                }
                num /= 10;
            }
            n--;
        }

        System.out.println(ans);
    }
}
